Imports System.Linq
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports SISSAT.BusinessLayer.DomainModels
Imports SISSAT.DataAcessLayer.StatementSources
Imports SISSAT.DataAcessLayer.PersistentStorage
Imports SISSAT.BusinessLayer.Utilities

Namespace Services
    Public Class ExaminationTypeService
        Inherits ServiceBase
        Implements IExaminationTypeService

        Public Sub Create(ByVal name As String, ByVal description As String, ByVal groupId As Integer, ByVal createdBy As Integer) Implements IExaminationTypeService.Create
            StatementSource = New CreateExaminationTypeStatementSource(name, description, groupId, createdBy)
            Dim nonQuery As Integer = DbHelper.ExecuteNonQuery(StatementSource)
        End Sub

        Public Sub Delete(examinationTypeId As Integer) Implements IExaminationTypeService.Delete
            StatementSource = New DeleteExaminationTypeStatementSource(examinationTypeId)
            Dim nonQuery As Integer = DbHelper.ExecuteNonQuery(StatementSource)
        End Sub

        Public Sub Edit(entity As ExaminationType, modifiedBy As Integer) Implements IExaminationTypeService.Edit
            StatementSource = New UpdateExaminationTypeStatementSource(entity.ExaminationTypeId, entity.Name, entity.Description, entity.GroupId, modifiedBy)
            Dim nonQuery As Integer = DbHelper.ExecuteNonQuery(StatementSource)
        End Sub

        Public Function ReadAll() As IEnumerable(Of ExaminationType) Implements IExaminationTypeService.ReadAll
            StatementSource = New ReadAllExaminationTypeStatementSource()
            Dim dataReader As SqlDataReader = DbHelper.ExecuteReader(StatementSource)

            Return DataMapper.MapDataToEntity(Of ExaminationType)(dataReader)
        End Function

        Public Function ReadAll(ByVal groupId As Integer) As IEnumerable(Of ExaminationType) Implements IExaminationTypeService.ReadAll
            StatementSource = New ReadAllExaminationTypeStatementSource(groupId)
            Dim dataReader As SqlDataReader = DbHelper.ExecuteReader(StatementSource)

            Return DataMapper.MapDataToEntity(Of ExaminationType)(dataReader)
        End Function

        Public Function ReadById(examinationTypeId As Integer) As ExaminationType Implements IExaminationTypeService.ReadById
            StatementSource = New ReadByExaminationTypeIdStatementSource(examinationTypeId)
            Dim dataReader As SqlDataReader = DbHelper.ExecuteReader(StatementSource)

            Return DataMapper.MapDataToEntity(Of ExaminationType)(dataReader).FirstOrDefault()
        End Function
    End Class
End Namespace